﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using JKZP.Helpers;
using System.Data.OracleClient;
using JKZP.Model;

namespace JKZP.DAL
{
    public class VEHDAL
    {
        private VEH ToCustomer(DataRow row)
        {
            VEH veh = new VEH();
            veh.Hphm = (string)row["HPHM"];
            veh.Hpzl = (string)row["HPZL"];
            veh.Lxdh = (string)row["LXDH"];
            veh.Sjhm = (string)row["SJHM"];
            veh.Syr = (string)row["SYR"];
            return veh;
        }
        public VEH[] GetAll()
        {
            DataTable table = new DataTable();
            table = SqlHelper.ExecuteDataTable("select hphm,hpzl,syr,lxdh,sjhm from VEH");
            VEH[] vehs = new VEH[table.Rows.Count];
            for (int i = 0; i < table.Rows.Count;i++ )
            {
                DataRow row = table.Rows[i];
                vehs[i] = ToCustomer(row);
            }
            return vehs;
        }

        public string GetById(string hphm,string hpzl)
        {
            DataTable dt = SqlHelper.ExecuteDataTable(@"select sjhm from VEH 
                    where hphm=:hphm and hpzl=:hpzl",
                new OracleParameter(":hphm", hphm),
                new OracleParameter(":hpzl", hpzl));
            if (dt.Rows.Count <= 0)
            {
                return null;
            }
            else if (dt.Rows.Count > 1)
            {
                throw new Exception("严重错误，查出多条数据！");
            }
            else
            {
                DataRow row = dt.Rows[0];
                string value = row[0].ToString();
                return value;
            }
        }
    }
}
